package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.MenuVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resource")
@Api(tags = "菜单资源管理")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;


    @PostMapping("/list")
    @ApiOperation(value = "菜单资源列表",notes = "菜单资源列表")
    @ApiImplicitParam(name = "resourceDto",value = "菜单资源DTO对象",required = true,dataType = "ResourceDto")
    public ResponseResult findList(@RequestBody ResourceDto resourceDto){
       List<ResourceVo> resourceVoList = resourceService.findList(resourceDto);
       return ResponseResult.success(resourceVoList);
    }

    @PostMapping("/tree")
    @ApiOperation(value = "菜单资源树形",notes = "菜单资源树形")
    @ApiImplicitParam(name = "resourceDto",value = "菜单资源DTO对象",required = true,dataType = "ResourceDto")
    public ResponseResult tree(@RequestBody ResourceDto resourceDto){
        TreeVo resourceVoList = resourceService.tree(resourceDto);
        return ResponseResult.success(resourceVoList);
    }


    @PutMapping
    @ApiOperation(value = "新增菜单资源",notes = "新增菜单资源")
    @ApiImplicitParam(name = "resourceDto",value = "菜单资源DTO对象",required = true,dataType = "ResourceDto")
    public ResponseResult add(@RequestBody ResourceDto resourceDto){
        resourceService.add(resourceDto);
        return ResponseResult.success(true);
    }

    @PatchMapping
    @ApiOperation(value = "资源修改",notes = "资源修改")
    @ApiImplicitParam(name = "resourceDto",value = "菜单资源DTO对象",required = true,dataType = "ResourceDto")
    public ResponseResult update(@RequestBody ResourceDto resourceDto){
        resourceService.update(resourceDto);
        return ResponseResult.success(true);
    }

    @PostMapping("/enable")
    @ApiOperation(value = "启用禁用",notes = "启用禁用")
    @ApiImplicitParam(name = "resourceDto",value = "菜单资源DTO对象",required = true,dataType = "ResourceDto")
    public ResponseResult<Boolean> isEnable(@RequestBody ResourceDto resourceDto){
        resourceService.enableDisable(resourceDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/{menuId}")
    @ApiOperation(value = "资源删除",notes = "资源删除")
    public ResponseResult delete(@ApiParam(value = "资源id", required = true)
                                 @PathVariable("menuId") String id) {
        resourceService.delete(id);
        return ResponseResult.success();
    }




}
